package com.example.auth.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.auth.config.ResultUtil;
import com.example.auth.config.exception.GlobalExcetion;
import com.example.auth.domain.DataNodeConfig;
import com.example.auth.domain.User;
import com.example.auth.domain.vo.UserVo;
import com.example.auth.service.DataNodeConfigService;
import com.example.auth.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;


    @GetMapping("/search")
    public User searchUserApi(@RequestParam("username") String username){
        User user=userService.findByUsername(username);
        return user;
    }

    @PostMapping("/registerUser")
    public JSONObject registerUser(@RequestBody UserVo vo) throws GlobalExcetion {
        User user=new User();
        BeanUtils.copyProperties(vo,user);
        userService.registerUser(user);
        return ResultUtil.successInfo("操作成功");
    }

    @GetMapping("/dataNodeByUserName")
    public DataNodeConfig findNodeByUsername(@RequestParam("username") String username){
        return userService.findDataNodeByUserName(username);
    }


}
